#!/usr/bin/env python
#ecoding = utf-8
__author__ = 'lihao'
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plot
from math import exp
target_url = ("https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data")
abalone = pd.read_csv(target_url, header=None, prefix="V")
abalone.columns = ['Sex', 'Length', 'Diameter', 'Height', 'Whole wt', 'Shucked wt', 'Viscera wt', 'Shell wt', 'Rings']

print(abalone.head())
print(abalone.tail())

summary = abalone.describe()
print(summary)

minRings = summary.ix[3, 7]
maxRings = summary.ix[7, 7]
nrows = len(abalone.index)

# print(minRings)
# print(maxRings)
print minRings, maxRings

for i in range(nrows):
    dataRow = abalone.ix[i, 1:8]
    labelColor = (abalone.ix[i, 8]-minRings)/(maxRings-minRings)
    dataRow.plot(color = plot.cm.RdYlBu(labelColor),alpha=0.5)
plot.xlabel("1")
plot.ylabel("2")
plot.show()

meanRings = summary.ix[1, 7]
sdRings = summary.ix[2, 7]
for i in range(nrows):
    dataRow = abalone.ix[i,1:8]
    normTarget = (abalone.ix[i, 8] -meanRings)/sdRings
    labelColor = 1.0/(1.0+exp(-normTarget))
    dataRow.plot(color=plot.cm.RdYlBu(labelColor),alpha = 0.5)
plot.xlabel("1")
plot.ylabel("2")
plot.show()
